<?php
session_start();


include ("db/db_connect.php"); 
include_once("cript.php");

$senhaatual=$_POST["txtatuSenha"];
$senha=$_POST["txtSenha"];
$confsenha=$_POST["txtConfSenha"];
$login=$_SESSION['coAdmin'];

$sql="select * from tab_admin where login='$login'";
$qry = @mysql_query($sql) or die(mysql_error());
$row= mysql_fetch_array($qry);
		
$desc_senha=$Criptografia->Descriptografa($row['senha']);



if($senhaatual!=$desc_senha){
	echo "<script>alert('Confira sua senha atual!');history.back();</script>";				 
}else{
			if ($senha==$confsenha){
			
			$senha_crip=$Criptografia->Criptografa($senha);
			
				$sql="update tab_admin set senha='$senha_crip' where login='$login'";
				mysql_query($sql, $db_conn)or die("<script>\n alert('Erro ao Atualizar!'); \n history.back();\n</script>\n");

/*
######################	
Inicio - Tabela de Log
######################	
*/
$date=getdate();
$data= $date["year"]."-".$date["mon"]."-".$date["mday"]." ".$date["hours"].":".$date["minutes"].":".$date["seconds"];
$usuario=$_SESSION['nomeAdmin'];
$id_usuario=$_SESSION['idAdmin'];
$obs=" SQL: ".str_replace("'","\"",$sql)." ";

	$sql1="insert into tab_log(id_usuario, usuario, date, observacao) values($id_usuario,'$usuario','$data','$obs')";
	mysql_query($sql1, $db_conn);
	unset($sql1);
/*
######################	
FIM - Tabela de Log
######################	
*/			
	unset($sql);
	echo "<script>\n alert('Atualizado com sucesso!'); \ndocument.location='index.php';\n</script>\n";			
			
			}else{
				echo "<script>alert('Confira sua senha e confirme-a!');history.back();</script>";
			}
}
?>